package cn.zhy.basic.service.impl;

import cn.zhy.basic.mapper.BaseMapper;
import cn.zhy.basic.query.BaseQuery;
import cn.zhy.basic.service.IBaseService;
import cn.zhy.basic.util.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.management.Query;
import java.util.List;


@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;


    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    @Transactional
    @Override
    public void save(T t) {
        baseMapper.save(t);
    }
    @Transactional
    @Override
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    @Transactional
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public PageList<T> queryPage(BaseQuery baseQuery) {

        Long count = baseMapper.queryCount(baseQuery);
        if (count==0){
        }
        List<T> data = baseMapper.queryData(baseQuery);
        return new PageList<T>(count,data);
    }

    //批量删除
    @Transactional
    @Override
    public void patchDelete(List<Long> ids) {
        baseMapper.patchDelete(ids);
    }

}
